<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

	<link href="../../../static/font-awesome-4.7.0/css/font-awesome.min.css" rel="stylesheet">
	<link rel="stylesheet" href="../../../static/vui/css/vui.css">

	<script type="text/javascript" src="../../../static/js/jquery-1.9.1.min.js"></script>
	<script type="text/javascript" src="../../../static/js/jquery.cookie.min.js"></script>
	<script type="text/javascript" src="../../../static/layer/layer.js"></script>
	<script type="text/javascript" src="../../../static/vui/js/vui.js"></script>
	<script type="text/javascript" src="../../../static/vui/js/datagrid.js"></script>
	<script type="text/javascript" src="../../../static/js/common.js"></script>
</head>
<body>

<div class="vui-form-top">
	<div id="formArea">
		<table class="from-table">
			<tr>
				<td class="label">
					<label>角色名称</label>
				</td>
				<td>
					<input type="text" autocomplete="off" class="input" name="name"/>
				</td>
				<td>
					<button class="button" id="query"><span>查询</span></button>
					<button class="button" id="create"><span>新增</span></button>
				</td>
			</tr>
		</table>

	</div>
</div>
<div id="table"></div>

<script>
var editArea = 	['400px', '350px'];

$(function(){
    $('#create').click(function(){
        app.window(layer,{
            title:'添加角色',
            area: editArea,
            content: 'role_add.html'
        });
    });

    $('#query').click(function(){
        $('#table').datagrid("reload",app.serializeForm());
    });

    $('#companyId').search({
        id:'companyId',
        name:'companyId',
        click:function(){
            app.window(layer,{
                title:'机构选择',
                btn:[],
                area: ['600px', '600px'],
                content: '../../common/company_tree.html?index=-1&queryId=companyId'
            });
        }
    });

    var company = {companyId:app.getCompanyId(),companyId_text:app.getCompanyName()};
    app.resetForm(company);

    $('#table').datagrid({
        width:500,simplePagination:true,
        url:app.BASE_API_URL+'role/page',
        loadSuccess:loadDataSuccess,
        queryParams:{loginCompanyId:app.getCompanyId()},
        columns:[
            {field:'name',title:'角色名称',width:100},
            {field:'comments',title:'角色描述',width:100},
            {title:'操作',width:100,formatter:function(row){
                return app.getOpt(row.id,'授权','green')+app.getOpt(row.id,'编辑','edit')+app.getOpt(row.id,'删除','del');
            }}
        ]
    });
});

function loadDataSuccess(){
    $('.vui-opt-del').click(function(){
        var id = $(this).data('id');
        layer.confirm('确定要删除选中的记录吗？', {icon: 3, title:'提示'}, function(index){
            app.request({
                url:'role/delete',
                data:{id:id,status:0},
                success:function (resp) {
					app.actionSuccess_index(resp,index);
                }
            });

        });
	});

    $('.vui-opt-edit').click(function(){
        var row = $(this).parent().parent().parent().data();
        app.window(layer,{
            area: editArea,
            content: 'role_add.html?id='+row.id+'&data='+encodeURIComponent(JSON.stringify(row))
        });
    });

    $('.vui-opt-green').click(function(){

        var row = $(this).parent().parent().parent().data();
        app.window(layer,{
            area: 	['360px', '600px'],
			title:'角色授权【'+row.name+'】',
            content: 'menu_tree.html?id='+row.id
        });
    });
}
</script>

</body>
</html>